package com.example.demo.student.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.demo.student.entity.Student;
import com.example.demo.student.service.IStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuanzheng
 * @since 2021-05-27
 */
@RestController
@RequestMapping("/student")
@Api(value = "学生", tags = {"增删改查"})
public class StudentController {

    @Autowired
    private IStudentService studentService;

    @GetMapping("/get")
    @ApiOperation(value = "获取学生列表")
    public List<Student> getStudents() {
        LambdaQueryWrapper<Student> query = Wrappers.lambdaQuery(Student.class);
        return studentService.list(query);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增学生信息")
    public boolean addStudent(@ApiParam Student student) {
        return studentService.save(student);
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改学生信息")
    public boolean updateStudent(@ApiParam Student student) {
       return studentService.updateById(student);
    }

    @GetMapping("/del")
    @ApiOperation(value = "删除学生信息")
    public boolean deleteStudent(@ApiParam(name = "id",value = "唯一ID") Integer id) {
        return studentService.removeById(id);
    }


}

